<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<link rel="stylesheet" href="../layui/css/layui.css" media="all">
		<script type="text/javascript" src="../layui/layui.js"></script>
		<script src="../js/jquery-1.8.3.min.js" type="text/javascript"></script>
	</head>
	<body>
		<form class="layui-form" action="">
			<div class="layui-form-item">
				<label class="layui-form-label">职业</label>
				<div class="layui-input-block">
					<input type="text" name="name" lay-verify="name" autocomplete="off" placeholder="职业" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">工作</label>
				<div class="layui-input-block">
					<input type="text" name="remanrk" lay-verify="remanrk" autocomplete="off" placeholder="工作" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<div class="layui-input-block">
					<button type="submit" class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
					<button type="reset" class="layui-btn layui-btn-primary">重置</button>
				</div>
			</div>
		</form>
	</body>

	<script>
		layui.use(['form', 'layedit', 'laydate'], function() {
			var form = layui.form,
					layer = layui.layer;


			//自定义验证规则
			form.verify({
				name: function (value) {
					if (value.length < 2) {
						return '工作至少得5个字符啊';
					}
				},
				remanrk: function (value) {
					if (value.length < 5) {
						return '职业至少得5个字符啊';
					}
				},
				content: function (value) {
					layedit.sync(editIndex);
				}
			});


			//监听提交
			form.on('submit(demo1)', function (data) {
				$.ajax({
					url: 'addJob.do',
					data: data.field,
					type: 'post',
					dataType: 'json',
					success: function (data) {
						if (data.code == 1) {
							alert(data.info);
							location.reload(); //添加成功后再刷新
							window.location.href="position.html";
						} else {
							layer.alert("添加失败");
						}
					}
				});
				return false;
			});
		});
	</script>

</html>
